package com.hutao.sso.service.impl.authority;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hutao.sso.dataSource.TargetDataSource;
import com.hutao.sso.mapper.newAuthority.UserRolesMapper;
import com.hutao.sso.pojo.newAuthority.UserRoles;
import com.hutao.sso.service.authority.UserRolesService;
import com.hutao.sso.util.Result;
import com.hutao.sso.util.StringUtil;

@Transactional
@Service
public class UserRolesServiceImpl implements UserRolesService{
	@Autowired
	private UserRolesMapper userRoleMapper;

	@TargetDataSource(name = "ds1")
	@Override
	public int insertUserRoles(UserRoles usersRoles) {
		return userRoleMapper.insertUserRoles(usersRoles);
	}

	@TargetDataSource(name = "ds1")
	@Override
	public int deleteUserRolesByuserHospitalId(Map<String, Object> params) {
		return userRoleMapper.deleteUserRolesByuserHospitalId(params);
	}

	@TargetDataSource(name = "ds1")
	@Override
	public Result insertUserRolesList(List<UserRoles> userRoleList, Map<String, Object> params) {
		userRoleMapper.deleteUserRolesByuserHospitalId(params);
		if(userRoleList != null && userRoleList.size() > 0) {
			for(UserRoles userRole: userRoleList) {
				userRole.setId(StringUtil.getId());
				userRoleMapper.insertUserRoles(userRole);
			}
		}
		return new Result(true, "分配角色成功!");
	}

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public long findCountByRoleId(Map<String, Object> params) {
		return userRoleMapper.findCountByRoleId(params);
	}

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public List<Map<String, Object>> findUserRoleListByUserId(Map<String, Object> params) {
		return userRoleMapper.findUserRoleListByUserId(params);
	}

	
	
	
}
